//
// Created by Administrator on 2021/9/28.
//

#ifndef HELLOOPENGL_LOG_H
#define HELLOOPENGL_LOG_H

#define MSG_LENGTH	2048 //最大消息长度

#include <string>
#include <ctime>
#include <cstdarg>
#include "iostream"
#include "../exception/HelloAssert.h"
#include "../core/String.h"

/**
 * debug输出宏
 */
#define log_debug(frm, argc...) { \
    String s;                     \
    s += __FILE__;                \
    s += " - [";                  \
    s += __func__;                \
    s +=  ",";                    \
    s += String::float2string(__LINE__); \
    s += "] " ;                          \
    s += frm;                      \
    Log::printlog(LogLevel::DEBUG, s.c_str(), ##argc); \
};

/**
 * info输出宏
 */
#define log_info(frm, argc...) { \
    String s;                     \
    s += __FILE__;                \
    s += " - [";                  \
    s += __func__;                \
    s +=  ",";                    \
    s += String::float2string(__LINE__); \
    s += "] ";                           \
    s += frm;                         \
    Log::printlog(LogLevel::INFO, s.c_str(), ##argc);   \
};

/**
 * warn输出宏
 */
#define log_warn(frm, argc...) { \
    String s;                     \
    s += __FILE__;                \
    s += " - [";                  \
    s += __func__;                \
    s +=  ",";                    \
    s += String::float2string(__LINE__); \
    s += "] ";                           \
    s += frm;                         \
    Log::printlog(LogLevel::WARN, s.c_str(), ##argc);   \
};

/**
 * error输出宏
 */
#define log_error(frm, argc...) { \
    String s;                     \
    s += __FILE__;                \
    s += " - [";                  \
    s += __func__;                \
    s +=  ",";                    \
    s += String::float2string(__LINE__); \
    s += "] ";                           \
    s += frm;                          \
    Log::printlog(LogLevel::ERR, s.c_str(), ##argc);   \
};

/**
 * 日志级别
 */
enum LogLevel {
    DEBUG,INFO,WARN,ERR
};

/**
 * 日志
 */
class Log {
public:
    /**
     * 输出日志
     * @param LEVEL 级别
     * @param msg 日志
     * @param ...
     */
    static void printlog(LogLevel level, const char* msg, ...);
};
#endif //HELLOOPENGL_LOG_H
